package cn.yj.frame.spring.event;

import cn.yj.frame.annotation.RpcService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author Liyj
 */
public class RpcSpringBeanPostProcessor implements BeanPostProcessor {

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		RpcService service = bean.getClass().getAnnotation(RpcService.class);
		if (service != null) {
			// 提前缓存-容器启动成功后暴露接口
			RpcSpringApplicationStartingListener.SERVICE_BEAN_CACHE.put(beanName, bean);
		}

		return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
	}
}
